package com.mingyuan.library.provider.lending.controller;

import com.mingyuan.library.infra.common.anntation.LogWriter;
import com.mingyuan.library.infra.common.anntation.RestResponse;
import com.mingyuan.library.provider.common.dto.Result;
import com.mingyuan.library.provider.lending.model.command.PlaceHoldCommand;
import com.mingyuan.library.provider.lending.model.command.PlaceOnHoldCommand;
import com.mingyuan.library.provider.lending.model.dto.PatronProfileDTO;
import com.mingyuan.library.provider.lending.model.query.PatronProfileQuery;
import com.mingyuan.library.provider.lending.presentation.PatronProfilePresentation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 读者档案相关接口
 *
 * @author yangzk
 * @version 1.0.0
 * @date 2024.01.05 18:50
 */
@RestController
@Api(tags = "读者档案信息相关接口")
public class PatronProfileController {
    /**
     * 读者档案信息相关接口
     */
    @Resource
    private PatronProfilePresentation patronProfilePresentation;

    /**
     * 获取读者档案
     *
     * @param patronProfileQuery 读者档案信息查询条件
     * @return 读者档案信息
     * @author yangzk
     * @date 2024/1/5 18:53
     **/
    @RestResponse
    @ApiOperation(value = "获取读者档案")
    @GetMapping("/v1/findPatronProfile")
    @LogWriter(prefix = "Client请求获取读者档案")
    public Result<PatronProfileDTO> findPatronProfile(@ApiParam(name = "patronProfileQuery", value = "读者档案信息查询条件", required = true) PatronProfileQuery patronProfileQuery) {
        return Result.success(patronProfilePresentation.findPatronProfile(patronProfileQuery));
    }

    /**
     * 读者预定图书
     *
     * @param placeHoldCommand 预定图书命令请求参数
     * @return true 成功 false 失败
     * @author yangzk
     * @date 2024/1/5 19:45
     **/
    @RestResponse
    @ApiOperation(value = "读者预定图书")
    @PostMapping("/v1/placeHold")
    @LogWriter(prefix = "Client请求读者预定图书")
    @ApiImplicitParam(name = "placeHoldCommand", value = "预定图书命令请求参数", required = true)
    public Result<Boolean> placeHold(@RequestBody PlaceHoldCommand placeHoldCommand) {
        return Result.success(patronProfilePresentation.placeOnHold(placeHoldCommand));
    }

    /**
     * 读者预定V2 优化版本
     * @author yangzk
     * @param
     * @date 2024/1/18 08:20
     * @return
     **/
    @RestResponse
    @ApiOperation(value = "读者预定图书")
    @PostMapping("/v2/placeOnHold")
    @LogWriter(prefix = "Client请求读者预定图书")
    @ApiImplicitParam(name = "placeOnHoldCommand", value = "预定图书命令请求参数", required = true)
    public Result<Boolean> placeOnHold(@RequestBody PlaceOnHoldCommand placeOnHoldCommand){
        return Result.success(patronProfilePresentation.placeOnHold(placeOnHoldCommand));
    }

}
